package com.luckyframe.project.jmeter.jmeterTestCase.controller;

import cn.hutool.core.util.XmlUtil;
import com.alibaba.fastjson.JSON;
import com.luckyframe.common.utils.StringUtils;
import com.luckyframe.common.utils.file.FileUploadUtils;
import com.luckyframe.common.utils.poi.ExcelUtil;
import com.luckyframe.common.utils.security.ShiroUtils;
import com.luckyframe.framework.aspectj.lang.annotation.Log;
import com.luckyframe.framework.aspectj.lang.enums.BusinessType;
import com.luckyframe.framework.config.JmeterConfig;
import com.luckyframe.framework.config.LuckyFrameConfig;
import com.luckyframe.framework.web.controller.BaseController;
import com.luckyframe.framework.web.domain.AjaxResult;
import com.luckyframe.framework.web.page.TableDataInfo;
import com.luckyframe.project.jmeter.jmeterAlertConfig.service.IJmeterAlertConfigService;
import com.luckyframe.project.jmeter.jmeterNode.domain.JmeterNode;
import com.luckyframe.project.jmeter.jmeterNode.service.IJmeterNodeService;
import com.luckyframe.project.jmeter.jmeterTestCase.domain.CaseNodeList;
import com.luckyframe.project.jmeter.jmeterTestCase.domain.DependencyFile;
import com.luckyframe.project.jmeter.jmeterTestCase.domain.JmeterTestCase;
import com.luckyframe.project.jmeter.jmeterTestCase.domain.Point;
import com.luckyframe.project.jmeter.jmeterTestCase.service.IJmeterTestCaseService;
import com.luckyframe.project.jmeter.jmeterTestPlan.controller.JmeterTestPlanController;
import com.luckyframe.project.system.project.domain.Project;
import com.luckyframe.project.system.project.service.IProjectService;
import com.luckyframe.project.testmanagmt.projectCaseModule.domain.ProjectCaseModule;
import com.luckyframe.project.testmanagmt.projectCaseModule.service.IProjectCaseModuleService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.jmeter.report.core.DataContext;
import org.apache.jmeter.report.processor.ResultData;
import org.apache.jmeter.report.processor.ResultDataVisitor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

/**
 * jmeter测试用例 信息操作处理
 * 
 * @author lancelot
 * @date 2020-09-17
 */
@Controller
@RequestMapping("/jmeter/jmeterTestCase")
public class JmeterTestCaseController extends BaseController
{

	private static final Logger log = LoggerFactory.getLogger(JmeterTestPlanController.class);


	private String prefix = "jmeter/jmeterTestCase";
	
	@Autowired
	private IJmeterTestCaseService jmeterTestCaseService;

	@Autowired
	private IJmeterNodeService jmeterNodeService;

	@Autowired
	private IProjectService projectService;

	@Autowired
	private IProjectCaseModuleService projectCaseModuleService;

	@Autowired
	private IJmeterAlertConfigService jmeterAlertConfigService;

	@Autowired
	private JmeterConfig jmeterConfig;

	@RequiresPermissions("jmeter:jmeterTestCase:view")
	@GetMapping()
	public String jmeterTestCase(ModelMap mmap)
	{

		List<Project> projects=projectService.selectProjectAll(0);
		mmap.put("projects", projects);
		if(projects.size()>0){
			ProjectCaseModule projectCaseModule = new ProjectCaseModule();
			if(StringUtils.isNotEmpty(ShiroUtils.getProjectId())){
				mmap.put("defaultProjectId", ShiroUtils.getProjectId());
				projectCaseModule = projectCaseModuleService.selectProjectCaseModuleParentZeroByProjectId(ShiroUtils.getProjectId());
			}
			mmap.put("projectCaseModule", projectCaseModule);
		}
	    return prefix + "/jmeterTestCase";
	}



	@GetMapping("/selectJmeterNode")
	public String projectPlanCase(@RequestParam("caseId") Long caseId, ModelMap mmap)
	{

		JmeterTestCase testCase = jmeterTestCaseService.selectJmeterTestCaseById(caseId);
		String nodeIds = testCase.getNodeIds();
		if(StringUtils.isNotEmpty(nodeIds)){
			List<Long> ids = JSON.parseArray(nodeIds, Long.class);
			List<JmeterNode> nodes = jmeterNodeService.selectByIdList(ids);
			if(CollectionUtils.isNotEmpty(nodes)){
				List<Long> nodeIdList = nodes.stream().map(JmeterNode::getId).collect(toList());
				mmap.put("nodeIdList", nodeIdList);
			}
		}else {
			mmap.put("nodeIdList", new ArrayList<>());
		}

		return prefix+"/selectJmeterNode";
	}


	/**
	 * 保存测试计划用例操作
	 * @author Seagull
	 * @date 2019年9月30日
	 */
	@RequestMapping(value = "/saveCaseNode",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public AjaxResult savePlanCase(@RequestBody CaseNodeList caseNodeList)
	{
		Long caseId = caseNodeList.getCaseId();
		JmeterTestCase testCase = jmeterTestCaseService.selectJmeterTestCaseById(caseId);
		testCase.setNodeIds(JSON.toJSONString(caseNodeList.getNodeIdList()));
		jmeterTestCaseService.updateJmeterTestCase(testCase);
		return toAjax(1);
	}


	/**
	 * 查询jmeter测试用例列表
	 */
	@RequiresPermissions("jmeter:jmeterTestCase:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(JmeterTestCase jmeterTestCase)
	{
		startPage();
        List<JmeterTestCase> list = jmeterTestCaseService.selectJmeterTestCaseList(jmeterTestCase);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出jmeter测试用例列表
	 */
	@RequiresPermissions("jmeter:jmeterTestCase:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmeterTestCase jmeterTestCase)
    {
    	List<JmeterTestCase> list = jmeterTestCaseService.selectJmeterTestCaseList(jmeterTestCase);
        ExcelUtil<JmeterTestCase> util = new ExcelUtil<JmeterTestCase>(JmeterTestCase.class);
        return util.exportExcel(list, "jmeterTestCase");
    }
	
	/**
	 * 新增jmeter测试用例
	 */
	@GetMapping("/add")
	public String add(ModelMap map)
	{
		List<JmeterNode> jmeterNodes = jmeterNodeService.selectJmeterNodeList(new JmeterNode());
		List<JmeterTestCase> cases = jmeterTestCaseService.selectJmeterTestCaseList(new JmeterTestCase());
		map.put("nodes",jmeterNodes);
		map.put("cases",cases);


		List<Project> projects = projectService.selectProjectAll(0);
		map.put("projects", projects);
		if (projects.size() > 0) {
			ProjectCaseModule projectCaseModule;
			if (StringUtils.isNotEmpty(ShiroUtils.getProjectId())) {
				map.put("defaultProjectId", ShiroUtils.getProjectId());
				projectCaseModule = projectCaseModuleService
						.selectProjectCaseModuleParentZeroByProjectId(ShiroUtils.getProjectId());
			} else {
				projectCaseModule = projectCaseModuleService
						.selectProjectCaseModuleParentZeroByProjectId(projects.get(0).getProjectId());
			}
			map.put("projectCaseModule", projectCaseModule);
		}

		return prefix + "/add";
	}

	/**
	 * 新增保存jmeter测试用例
	 */
	@RequiresPermissions("jmeter:jmeterTestCase:add")
	@Log(title = "jmeter测试用例", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(@RequestBody JmeterTestCase jmeterTestCase)
	{

		List<DependencyFile> dependencyFiles = jmeterTestCase.getDependencyFiles();
		jmeterTestCase.setAdditionFiles(JSON.toJSONString(dependencyFiles));
		jmeterTestCase.setNodeIds(JSON.toJSONString(jmeterTestCase.getNodeIdList()));

		Long relProjectId = jmeterTestCase.getRelProjectId();
		if(relProjectId!=null){
			Project project = projectService.selectProjectById(relProjectId.intValue());
			if(project!=null){
				jmeterTestCase.setRelProjectName(project.getProjectName());
			}
		}


		Long relModuleId = jmeterTestCase.getRelModuleId();
		if(relModuleId!=null){
			ProjectCaseModule module = projectCaseModuleService.selectProjectCaseModuleById(relModuleId.intValue());
			if(module!=null){
				jmeterTestCase.setRelModuleName(module.getModuleName());
			}
		}


		return toAjax(jmeterTestCaseService.insertJmeterTestCase(jmeterTestCase));
	}

	/**
	 * 修改jmeter测试用例
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		JmeterTestCase jmeterTestCase = jmeterTestCaseService.selectJmeterTestCaseById(id);
		jmeterTestCase.setNodeIdList(JSON.parseArray(jmeterTestCase.getNodeIds(),String.class));
		jmeterTestCase.setAddtionFilesList(JSON.parseArray(jmeterTestCase.getAdditionFiles(), DependencyFile.class));

		List<JmeterNode> jmeterNodes = jmeterNodeService.selectJmeterNodeList(new JmeterNode());
		List<JmeterTestCase> cases = jmeterTestCaseService.selectJmeterTestCaseList(new JmeterTestCase());

		mmap.put("nodes",jmeterNodes);
		mmap.put("cases",cases);
		mmap.put("jmeterTestCase", jmeterTestCase);

		List<Project> projects = projectService.selectProjectList(new Project());
		mmap.put("projects",projects);

		return prefix + "/edit";
	}
	
	/**
	 * 修改保存jmeter测试用例
	 */
	@RequiresPermissions("jmeter:jmeterTestCase:edit")
	@Log(title = "jmeter测试用例", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(@RequestBody JmeterTestCase jmeterTestCase)
	{
		List<DependencyFile> dependencyFiles = jmeterTestCase.getDependencyFiles();
		jmeterTestCase.setAdditionFiles(JSON.toJSONString(dependencyFiles));
		jmeterTestCase.setNodeIds(JSON.toJSONString(jmeterTestCase.getNodeIdList()));

		if(StringUtils.isEmpty(jmeterTestCase.getScriptLocation())){
			jmeterTestCase.setScriptLocation(null);
		}

		if(StringUtils.isEmpty(jmeterTestCase.getAdditionFiles()) || "[]".equals(jmeterTestCase.getAdditionFiles())){
			jmeterTestCase.setAdditionFiles(null);
		}

		return toAjax(jmeterTestCaseService.updateJmeterTestCase(jmeterTestCase));
	}


	/**
	 * 修改保存jmeter测试用例
	 */
	@GetMapping("/getById")
	@ResponseBody
	public AjaxResult getById(@RequestParam("caseId") Long caseId)
	{
		if(caseId==null||caseId==0){
			return AjaxResult.error("id为空");
		}

		long granularity=1000;//1s

		long total=0;  //total thread counts

		List<Point>  points=new ArrayList<>();

		JmeterTestCase testCase = jmeterTestCaseService.selectJmeterTestCaseById(caseId);

		long now = 0;

		points.add(new Point(now, 0));
		points.add(new Point(now + testCase.getThreadsDelay()*1000, 0));

		int numThreads = testCase.getThreadsNum();

		List<ThreadPeriod> threadPeriods = IntStream.range(0, numThreads).mapToObj(index ->
			 createThreadPeriod(index, testCase, now)
		).collect(toList());



		for (ThreadPeriod threadPeriod : threadPeriods) {
			points.add(new Point(threadPeriod.getStartTime(),++total));
		}

		for (ThreadPeriod threadPeriod : threadPeriods) {
			points.add(new Point(threadPeriod.getEndTime(),--total));
		}

		List<long[]> cartesianPoints = points.stream().map(Point::toArray).collect(toList());

		AjaxResult ajaxResult=new AjaxResult();
		ajaxResult.put("points",cartesianPoints);

		return ajaxResult;
	}


	private static  <T> void addResultToContext(
			String resultKey, Map<String, Object> storage, DataContext dataContext,
			ResultDataVisitor<T> visitor) {
		Object data = storage.get(resultKey);
		if (data instanceof ResultData) {
			ResultData result = (ResultData) data;

			dataContext.put(resultKey, result.accept(visitor));
		}
	}





	/***
	 *  @param threadIndex start with zero
	 * @param testCase
	 * @param tgStartTime
	 * @return
	 */
	private ThreadPeriod createThreadPeriod(int threadIndex, JmeterTestCase testCase, long tgStartTime) {

		int inUserCount = testCase.getStartUserCount();
		int outUserCount = testCase.getStopUserCount();

		if (inUserCount == 0) {
			inUserCount = testCase.getThreadsNum();
		}
		if (outUserCount == 0) {
			outUserCount = testCase.getThreadsNum();
		}

		int inUserCountBurst = Math.min(testCase.getStartUserBurst(), testCase.getThreadsNum());
		if (inUserCountBurst <= 0) {
			inUserCountBurst = inUserCount;
		}

		int rampUpBucket = threadIndex < inUserCountBurst ? 0
				: 1 + (threadIndex - inUserCountBurst) / inUserCount;
		int rampUpBucketThreadCount = threadIndex < inUserCountBurst ? inUserCountBurst : inUserCount;

		long threadGroupDelay = 1000L * testCase.getThreadsDelay();
		long ascentPoint = tgStartTime + threadGroupDelay;
		long inUserPeriod = 1000L * testCase.getStartUserPeriod();
		long additionalRampUp = 1000L * testCase.getRampUp() / rampUpBucketThreadCount;
		long flightTime = 1000L * testCase.getFlightTime();
		long outUserPeriod = 1000L * testCase.getStopUserPeriod();

		long rampUpDuration = 1000L * testCase.getRampUp();
		long iterationDuration = inUserPeriod + rampUpDuration;
		//number of complete iteration, ie full (in user time + rampup duration) used
		int iterationCountTotal = testCase.getThreadsNum() < inUserCountBurst ? 1
				: (int) Math.ceil((double) (testCase.getThreadsNum() - inUserCountBurst) / inUserCount);

		int lastIterationUserCount = (testCase.getThreadsNum() - inUserCountBurst) % inUserCount;
		if (lastIterationUserCount == 0) {
			lastIterationUserCount = inUserCount;
		}
		long descentPoint = ascentPoint + iterationCountTotal * iterationDuration + (1000L * testCase.getRampUp() / inUserCount) * lastIterationUserCount + flightTime;

		long rampUpBucketStartTime = ascentPoint + rampUpBucket * iterationDuration;
		int rampUpBucketThreadPosition = threadIndex < inUserCountBurst ? threadIndex
				: (threadIndex - inUserCountBurst) % inUserCount;

		long startTime = rampUpBucketStartTime + rampUpBucketThreadPosition * additionalRampUp;
		long endTime = descentPoint + outUserPeriod * (int) Math.floor((double) threadIndex / outUserCount);

		return new ThreadPeriod(startTime,endTime);
	}

	private static  class ThreadPeriod{
		private long startTime;

		private long endTime;

		public ThreadPeriod(long startTime, long endTime) {
			this.startTime = startTime;
			this.endTime = endTime;
		}

		public long getStartTime() {
			return startTime;
		}

		public void setStartTime(long startTime) {
			this.startTime = startTime;
		}

		public long getEndTime() {
			return endTime;
		}

		public void setEndTime(long endTime) {
			this.endTime = endTime;
		}
	}



	/**
	 * 修改保存jmeter测试用例
	 */
	@GetMapping("/showPressureGraph")
	public String showPressureGraph(@RequestParam("caseId") Long caseId, ModelMap mmap)
	{

		JmeterTestCase testCase = jmeterTestCaseService.selectJmeterTestCaseById(caseId);
		mmap.put("testCase",testCase);
		return prefix+"/showPressureGraph";
	}



	/**
	 * 上传驱动页面
	 * @param mmap 返回数据模型
	 * @author Seagull
	 * @date 2019年4月26日
	 */
	@GetMapping("/showUploadJar")
	public String showUploadJar(ModelMap mmap)
	{
		return prefix+"/uploadJar";
	}


	/**
	 * 删除jmeter测试用例
	 */
	@RequiresPermissions("jmeter:jmeterTestCase:remove")
	@Log(title = "jmeter测试用例", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jmeterTestCaseService.deleteJmeterTestCaseByIds(ids));
	}


	/**
	 * uploadjmx
	 * @author Seagull
	 * @date 2019年7月26日
	 */
	@PostMapping("/uploadjmx")
	@ResponseBody
	public AjaxResult uploadjmx(@RequestParam("drivenfile") MultipartFile file ) {
		JmeterTestCase testCase=new JmeterTestCase();
		try {
			if (!file.isEmpty()) {
				if (!Objects.requireNonNull(file.getOriginalFilename()).endsWith(FileUploadUtils.JMX_EXTENSION))
				{
					return error("只能是jmx脚本文件");
				}

				File jmxFile = FileUploadUtils.uploadJar(jmeterConfig.getScriptDir(), file);

				String content = FileUtils.readFileToString(jmxFile, Charset.forName("UTF-8"));

				Document xml = XmlUtil.readXML(content);

				testCase.setThreadsNum(getValue(xml,"ThreadGroup.num_threads"));
				testCase.setThreadsDelay(getValue(xml,"Threads initial delay"));
				testCase.setStartUserCount(getValue(xml,"Start users count"));
				testCase.setStartUserBurst(getValue(xml,"Start users count burst"));
				testCase.setStartUserPeriod(getValue(xml,"Start users period"));
				testCase.setStopUserCount(getValue(xml,"Stop users count"));
				testCase.setStopUserPeriod(getValue(xml,"Stop users period"));
				testCase.setRampUp(getValue(xml,"rampUp"));
				testCase.setFlightTime(getValue(xml,"flighttime"));
				testCase.setScriptLocation(jmxFile.getAbsolutePath());

				List<DependencyFile> dependencyFiles = getDependencyFiles(xml);

				AjaxResult ajaxResult = AjaxResult.success();
				ajaxResult.put("data", testCase);
				ajaxResult.put("dependencyFiles", dependencyFiles);

				return ajaxResult;

			}else{
				return error("文件为空");
			}
		} catch (Exception e) {
			return error(e.getMessage());
		}
	}


	/**
	 * uploadjmx
	 * @author Seagull
	 * @date 2019年7月26日
	 */
	@PostMapping("/uploadJmxAddtionFiles")
	@ResponseBody
	public AjaxResult uploadJmxAddtionFiles(@RequestParam("drivenfile") MultipartFile file, @RequestParam("name") String name ) {
		JmeterTestCase testCase=new JmeterTestCase();
		AjaxResult ajx= AjaxResult.success("上传成功");
		try {
			if (!file.isEmpty()) {
				File datafile = FileUploadUtils.uploadJar(jmeterConfig.getScriptDir(), file);

				Map map=new HashMap();
				String absolutePath = datafile.getAbsolutePath();
				map.put("absolutePath",absolutePath);

				ajx.put("data",map);
				return ajx;

			}else{
				return error("文件为空");
			}
		} catch (Exception e) {
			return error(e.getMessage());
		}
	}



	/**
	 * 复制用例
	 * @param caseId 用例ID
	 * @param mmap 返回数据模型
	 * @author lancelot
	 */
	@GetMapping("/copy/{caseId}")
	@ResponseBody
	public AjaxResult copy(@PathVariable("caseId") String caseId, ModelMap mmap)
	{
		if(StringUtils.isEmpty(caseId)){
			return AjaxResult.error("未选中要复制的条目");
		}

		List<Long> caseIds = Stream.of(caseId.split(",")).map(Long::valueOf).collect(Collectors.toList());
		List<JmeterTestCase> testCases = jmeterTestCaseService.selectByIdList(caseIds);

		for (JmeterTestCase testCase : testCases) {
			testCase.setCaseName("Copy【"+testCase.getCaseName()+"】");
			testCase.setId(null);
			testCase.setScriptName(null);
			testCase.setScriptLocation(null);
			testCase.setCreateBy(null);
			testCase.setUpdateBy(null);
			jmeterTestCaseService.insertJmeterTestCase(testCase);
		}

		return AjaxResult.success();
	}



	/**
	 * 通用下载请求
	 *
	 *
	 */
	@GetMapping("donwloadJmx")
	public void donwloadJmx(Long caseId, HttpServletResponse response, HttpServletRequest request)
	{
		try
		{
			JmeterTestCase testCase = jmeterTestCaseService.selectJmeterTestCaseById(caseId);
			if(testCase==null|| StringUtils.isEmpty(testCase.getScriptLocation())){
				throw new RuntimeException("无脚本文件");
			}

			response.setCharacterEncoding("utf-8");
			response.setContentType("multipart/form-data");
			response.setHeader("Content-Disposition",
					"attachment;fileName=" +  URLEncoder.encode(testCase.getScriptName(), "utf-8"));
			com.luckyframe.common.utils.file.FileUtils.writeBytes(testCase.getScriptLocation(), response.getOutputStream());

		}
		catch (Exception e)
		{
			log.error("下载文件失败", e);
		}
	}




	private int getValue(Document xml,String key) {
		Element element = XmlUtil.getElementByXPath("//kg.apc.jmeter.threads.SteppingThreadGroup/stringProp[@name='"+key+"']", xml);
		if(element==null){
			return 0;
		}

		Node firstChild = element.getFirstChild();

		if(firstChild==null){
			return 0;
		}

		if(StringUtils.isEmpty(firstChild.getNodeValue())){
			return 0;
		}

		return Integer.valueOf(firstChild.getNodeValue());
	}


	private List<DependencyFile> getDependencyFiles(Document xml) {
		String xpath="//CSVDataSet/stringProp[@name='filename']";

		NodeList nodeListByXPath = XmlUtil.getNodeListByXPath(xpath, xml);
		if(nodeListByXPath==null||nodeListByXPath.getLength()==0){
			return new ArrayList<>();
		}


		Set<DependencyFile> set=new HashSet<>();


		for (int i = 0; i < nodeListByXPath.getLength(); i++) {

			Node item = nodeListByXPath.item(i);

			DependencyFile dependencyFile=new DependencyFile();
			dependencyFile.setFilename(FilenameUtils.getName(item.getTextContent()));
			dependencyFile.setExtention(FilenameUtils.getExtension(item.getTextContent()));
			dependencyFile.setFileLocation(item.getTextContent());
			set.add(dependencyFile);
		}
		

		return new ArrayList<>(set);
	}


	public static void main(String[] args) {

		List<Integer> ylineValue=new ArrayList<>();

		int xlineCount=10;


		int threadsNum = 200;
		int threadsDelay = 1;
		int startUserCount =3;
		int startUserBurst = 2;
		int startUserPeriod = 4	;
		int stopUserCount = 6;
		int stopUserPeriod = 7;
		int flightTime = 50;
		int rampUp =5;



		int totalTime=threadsDelay;

		int totalThreads=startUserBurst;



		for(;;){
			ylineValue.add(totalThreads);


			totalThreads+=startUserCount;


			if(totalThreads>threadsNum){
				break;
			}else {
				totalTime+=startUserPeriod+rampUp;
			}

		}




		totalTime+=flightTime;


		for(;;){
			ylineValue.add(totalThreads);
			totalThreads-=stopUserCount;



			if(totalThreads<0){
				break;

			}else{
				totalTime+=stopUserPeriod;

			}

		}


		int step = totalTime / xlineCount;
		for (int i = 1; i <= xlineCount; i++) {

			System.out.println("step = " + step*i);
			System.out.println("totalTime = " + step*i/60+":"+step*i%60);

		}





		System.out.println("totalTime = " + totalTime/60+":"+totalTime%60);
		System.out.println("ylineValue = " + ylineValue);


	}



}
